#encoding = utf-8

#面板模板

#引入模块
import pygame
from pygame.locals import *
#import monster
from BasicsModules import BasicsMonster

class GamePanel(object):
    def __init__(self, win, player, playerName = "test"):
        self.win = win
        self.player = player
        self.name = playerName
        self.fullBlood = self.player.blood
        self.monsterCount = len(BasicsMonster.BasMonster.lstMonster)
        self.panelImage = pygame.image.load("images/panel/panel.png").convert_alpha()
        pygame.font.init()

    def drawPlayerBlood(self, blood):
        bloodFrame = (0, 0, 0)  # 黑色
        bloodColor1 = (204, 0, 0)  # 红色
        bloodColor2 = (255, 0, 0)  # 红色
        bloodColor3 = (155, 0, 0)  # 红色
        bloodBack1 = (176, 176, 176)  # 深灰色
        bloodBack2 = (212, 212, 212)  # 浅灰色
        bloodBack3 = (147, 147, 147)  # 深灰色
        #画左右竖线
        pygame.draw.line(self.win, bloodFrame, [99, 10], [99, 25], 1)
        pygame.draw.line(self.win, bloodFrame, [241, 10], [241, 25], 1)
        #画上横线
        pygame.draw.line(self.win, bloodFrame, [100, 10], [240, 10], 1)
        #画下横线
        pygame.draw.line(self.win, bloodFrame, [100, 25], [240, 25], 1)
        #画4条血线背景，看着有立体感
        pygame.draw.line(self.win, bloodBack1, [100, 12], [240, 12], 3)
        pygame.draw.line(self.win, bloodBack2, [100, 15], [240, 15], 3)
        pygame.draw.line(self.win, bloodBack1, [100, 18], [240, 18], 4)
        pygame.draw.line(self.win, bloodBack3, [100, 22], [240, 22], 4)
        #画血瓶
        image = pygame.image.load("images/panel/bloodbottle.png").convert_alpha()
        self.win.blit(image, (63, 3))
        #画血量
        pBlood = int(blood / self.fullBlood * 140) + 100
        if pBlood > 100:
            # 画4条血线，看着有立体感
            pygame.draw.line(self.win, bloodColor1, [100, 12], [pBlood, 12], 3)
            pygame.draw.line(self.win, bloodColor2, [100, 15], [pBlood, 15], 3)
            pygame.draw.line(self.win, bloodColor1, [100, 18], [pBlood, 18], 4)
            pygame.draw.line(self.win, bloodColor3, [100, 22], [pBlood, 22], 4)
        #画血数字
        intBlood = pygame.font.Font("fonts/msyh.ttf", 12)
        intBlood.set_bold(True)
        bloodImage = intBlood.render(str(blood) + "/%d"%self.fullBlood, True, (255, 255, 255))
        if blood >999:
            pointX = 136
        elif blood > 99:
            pointX = 143
        elif blood > 9 and blood < 100:
            pointX = 149
        else:
            pointX = 154
        self.win.blit(bloodImage, (pointX, 9))

    def drawHeadPortrait(self):
        imageSrc = ""
        if self.player.name == "pig":
            imageSrc = "images/panel/pig.png"
        elif self.player.name == "monkey":
            #imageSrc = "images/panel/pig.png"
            pass
        image = pygame.image.load(imageSrc).convert_alpha()
        self.win.blit(image, (0, 5))

    def drawMonsterCount(self):
        #画怪物图标
        image = pygame.image.load("images/panel/monster.png").convert_alpha()
        #统计怪物数量
        intCount = len(BasicsMonster.BasMonster.lstMonster)
        intMonsterCount = pygame.font.Font("fonts/msyh.ttf", 16)
        intMonsterCount.set_bold(True)
        textImage = intMonsterCount.render(str(intCount), True, (255, 255, 255))
        self.win.blit(image, (280, 3))
        self.win.blit(textImage, (320, 8))

    def drawPlayerSkill(self, skillStarCount = 5):
        # 画技能图标
        image = pygame.image.load("images/panel/hammer.png").convert_alpha()
        self.win.blit(image, (370, 3))
        intI = 0
        intStartPostion = 410
        while intI < skillStarCount:
            starImage = pygame.image.load("images/panel/skillstar.png").convert_alpha()
            self.win.blit(starImage, (intStartPostion, 10))
            intStartPostion += 20
            intI += 1

    def drawPlayerPower(self, powerCount = 0):
        # 画技能图标
        image = pygame.image.load("images/panel/power.png").convert_alpha()
        self.win.blit(image, (550, 2))


    def draw(self, blood):
        self.win.blit(self.panelImage, (0, 0))
        self.drawPlayerBlood(blood)
        self.drawHeadPortrait()
        self.drawMonsterCount()
        self.drawPlayerSkill()
        self.drawPlayerPower()


if __name__ == "__main__":
    pass